/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.com.transportes.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import pe.com.transportes.modelo.Cliente;


public class ClienteDAO {


    public void insertarcliente(Connection con,Cliente c) throws SQLException{

    String sql ="insert into cliente values (?,?,?,?,?,?,?,?)";
    PreparedStatement ps = con.prepareStatement(sql);


    System.out.println("codigo dao "+c.getCod_cliente());

    ps.setInt(1,c.getCod_cliente());
        ps.setString(2,c.getNom_cliente());
        ps.setString(3, c.getApe_cliente());
        ps.setInt(4,c.getDni());
        ps.setInt(5,c.getTelefono());
        ps.setString(6,c.getCorreo());
        ps.setString(7,c.getFnacimiento());
        ps.setString(8, c.getContraseña());

    ps.executeUpdate();
    }
public Cliente buscarcliente(Connection con,int codigo) throws SQLException{
     Cliente bean = new Cliente();
  String sql = "select * from cliente where cod_cliente=?";

        PreparedStatement ps = con.prepareStatement(sql);
        ps.setInt(1,codigo);

          ResultSet rs = ps.executeQuery();
        if(rs.next()){

          bean.setCod_cliente(rs.getInt(1));
        bean.setNom_cliente(rs.getString(2));
        bean.setApe_cliente(rs.getString(3));
        bean.setDni(rs.getInt(4));
        bean.setTelefono(rs.getInt(5));
         bean.setCorreo(rs.getString(6));
         bean.setFnacimiento(rs.getString(7));
        bean.setContraseña(rs.getString(8));
        }
        return bean;

}

   public ArrayList<Cliente> Listaclientes(Connection con) throws SQLException{

          ArrayList<Cliente> lista = new ArrayList<Cliente>();

  String sql = "select * from cliente";

        PreparedStatement ps = con.prepareStatement(sql);

          ResultSet rs = ps.executeQuery();
      while(rs.next()){
 Cliente bean = new Cliente();
           bean.setCod_cliente(rs.getInt(1));
        bean.setNom_cliente(rs.getString(2));
        bean.setApe_cliente(rs.getString(3));
        bean.setDni(rs.getInt(4));
        bean.setTelefono(rs.getInt(5));
         bean.setCorreo(rs.getString(6));
         bean.setFnacimiento(rs.getString(7));
        bean.setContraseña(rs.getString(8));

         lista.add(bean);
        }
        return lista;


}




}
